/* 
 *	Copyright (C) 2009-2010 miaohua
 *	http://code.google.com/p/lrcshower/
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */

#pragma once
#include "TypeDef.h"
#include "LayedWinTextRenderBase.h"

// Render text on window by GlyPhMericts
class CGlyPhMetricsTextRender:public CLayedWinTextRenderBase
{
public:
    // Construnctor & destructor
    CGlyPhMetricsTextRender();
    virtual ~CGlyPhMetricsTextRender(){}

	// Get the containing box size for LrcLine
    virtual SIZE GetLrcBoxSize(HWND RendWin, const tstring & LrcLine);
    // Before call render,call StartOneLine at first to let render do some initialization
	virtual bool StartOneLine(HWND RendWin, const tstring & Lrc, bool IsNew);
    // Render the text to assigned windows
    virtual bool Render(HWND RendWin, const tstring & Lrc, unsigned int FocusLen);
    // Rend background to assigned windows(only background no text!)
    virtual bool RenderBg(HWND RendWin);
    // Flush the painted buffer to screen
	virtual bool Flush(HWND RendWin, const tstring & Lrc, unsigned int FocusLen, bool IsNew);

private:
	// Help functions
    // Pre Render to get some data
	// bool PreRender(HWND RendWin, const tstring & Lrc, bool IsFocus, bool IsCpyData=true, BYTE ** MemBuf = NULL);
    // Draw background
    void DrawBackground(int Transparent,COLORREF BgClr,BYTE*MemBits);
    // Pre render the lrc line
    bool PreRender(HWND RendWin, const tstring & Lrc, bool IsFocus, bool ToDraw=true);
    // Helper draw function for DrawText&DrawShadow
    // RendType = 0 means focus
    //          = 1 means unfocus
    //          = 2 means shadow
	void DrawHelper(HDC MemDC, const tstring & Text, RECT RC, BYTE* MemBits, int RendType=0);
    // Part color accroding to height
    void MakeOneColor(BYTE Upper, BYTE Mid, BYTE Lower, BYTE * Clr, int Height);
    void MakeColorPart(COLORREF UpperClr, COLORREF MidClr, COLORREF LowerClr, BYTE * R, BYTE * G, BYTE * B, int Height);


    int m_WinSize;                               // Window size = Width * Height *4 ( which is in byte unit )
    DWORD m_EffWinWidth;                         // Effective width of window(round by 32)
    bool  m_HaveOffsetY;                         // Wether current focus line has to be offset
	short m_OffsetY;                             // Value of offset
};